// common头文件，跨平台定义，一些常量定义
// auth : WenYF

#ifndef FZJH_COMMON_H
#define FZJH_COMMON_H

#include <sys/types.h>
#include <stdio.h>

#define STDC_HEADERS
//#define HAVE_UNISTD_H
#ifdef STDC_HEADERS
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#elif HAVE_STRINGS_H
#include <strings.h>
#endif


#ifdef HAVE_UNISTD_H
#include <sys/time.h>
#include <unistd.h>
#else
#include <time.h>
#endif


#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifndef errno
extern int errno;
#endif

#if _MSC_VER
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define gettimeofday cocos2d::gettimeofday
#endif

typedef unsigned char byte;
typedef int BOOL;

#define FALSE 0
#define TRUE 1
//#define NULL 0
//#define malloc(x) 1
//#define free(x) NULL
//#define size_t int
#define NOT_FOUND_POSITION -1

//#define IFCLIENT_ENABLE_DEBUG

#ifdef _WIN32
#include <windows.h>
#include <mmSystem.h>
#else
#define ANDROID_DEBUG
#endif

#ifdef IFCLIENT_ENABLE_DEBUG

#ifdef ANDROID_DEBUG
#include <android/log.h>
#define  LOG_TAG    "ifclient_native"
#define logV(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define logD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
#define logW(...) __android_log_print(ANDROID_LOG_WARN,LOG_TAG,__VA_ARGS__)
#define logE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
#else 
#define logV(...) {printf(__VA_ARGS__); printf("\n");}
#define logD(...) {printf(__VA_ARGS__); printf("\n");}
#define logW(...) {printf(__VA_ARGS__); printf("\n");}
#define logE(...) {printf(__VA_ARGS__); printf("\n");}
#endif

#else

#define logV(...)
#define logD(...)
#define logW(...)
#define logE(...)

#endif

enum iferror {
    IF_OK = 0,
    IF_NOMEM,
    IF_HOOK,
    IF_ERROR
};

enum ifneterror {
    IF_NET_NODNS = 4,
    IF_NET_NOSOCK,
    IF_NET_NOCONN,
    IF_NET_RWERR,
    IF_NET_NOTSUPP,
    IF_NET_TLSFAIL,
    IF_NET_DROPPED,
    IF_NET_UNKNOWN
};

#define PACKET_TYPE_SESSION_OPEN 0x00
#define PACKET_TYPE_SESSION_CLOSE 0x01
#define PACKET_TYPE_MESSAGE 0x10
#define PACKET_TYPE_EVENT 0x20

#define DEFAULT_RET (byte)0xff

#endif
